未完待續
features = ['SMA_3','SMA_7','SMA_30','EMA_3','EMA_7','EMA_30','RSI','MACD','MACD_signal']
from pmdarima import auto_arima
# Standard steps for passing the data to auto_arima
model = auto_arima(df_train.y, exogenous=df_train[features], trace=True, error_action="ignore", suppress_warnings=True)
model.fit(df_train.y, exogenous=df_train[features])
forecast = model.predict(n_periods=len(df_valid), exogenous=df_valid[features])
df_valid["Forecast_ARIMAX"] = forecast
from sklearn.metrics import mean_absolute_error, mean_squared_error
fig = go.Figure()
fig.add_trace(go.Scatter(x=df_valid.date, y=df_valid.y, name='close'))
fig.add_trace(go.Scatter(x=df_valid.date, y=df_valid.Forecast_ARIMAX, name='Forecast_ARIMAX'))
fig.show()
print("RMSE of Auto ARIMAX:", np.sqrt(mean_squared_error(df_valid.y, df_valid.Forecast_ARIMAX)))
print("\nMAE of Auto ARIMAX:", mean_absolute_error(df_valid.y, df_valid.Forecast_ARIMAX))